package com.zx.cloud.security.utils;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.stream.Stream;

import lombok.Data;

/**
 * 微信模板消息类
 * @author zhaoxuan
 * @date 2022-04-11 14:48
 **/
@Data
public class TemplateMessage {
    @JSONField(name = "touser")
    private String user;
    @JSONField(name = "template_id")
    private String templateId;
    private Map<String, ColorAndValue> data;

    public TemplateMessage(String user, String templateId) {
        this.user = user;
        this.templateId = templateId;
        data = new HashMap<>();
    }

    public TemplateMessage addData(String keyword, String value,String color) {
        data.put(keyword, new ColorAndValue(value,color));
        return this;
    }

    public String toJsonStr() {
        return JSONObject.toJSONString(this);

    }

    @Data
    public class ColorAndValue {
        private String color;
        private String value;

        public ColorAndValue(String value, String color) {
            this.value = value;
            this.color = color;
        }
    }

    public static void main(String[] args) {
        Stream.generate(()->new Random().nextInt(10)).limit(100).forEach(System.out::println);
    }

}

